package com.blue.scheduled.task;

import com.blue.scheduled.logs.annotation.JobLog;
import com.blue.service.system.IDataSyncConfService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

@Slf4j
public class DataSyncTask extends QuartzJobBean {

    @Resource
    private IDataSyncConfService dataSyncConfService;

    @Override
    @JobLog
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        log.info("开始开始执行数据同步-----------------------------");
        JobDataMap dataMap = context.getMergedJobDataMap();
        String tableName = (String) dataMap.get("params");
        if (StringUtils.isNotBlank(tableName)) {
            log.info("本次同步的数据表名为：{}", tableName);
            dataSyncConfService.syncData(tableName);

        } else {
            dataSyncConfService.syncData("");
        }
        log.info("数据同步已完成----------------------------------");
    }
}
